#include<bits/stdc++.h>
using namespace std;
int T;
int n;
const int N = 1e6 + 10;
int a[N];
int color[N];
bool vis[N];
int sum;
int ans;
int main () {
    freopen("color.in","r",stdin);
   freopen("color.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> T;
    while(T --){
        memset(vis,0,sizeof(vis));
        cin >> n;
        ans = 0;
        sum = 0;
        for(int i = 1;i <= n;i ++){
            cin >> a[i];
            vis[a[i]] = 1;
        }
        for(int i = 1;i <= a[n];i ++){
            sum += vis[i];
        }
        if(sum == n){
            cout << 0 << endl;
            continue;
        }
        for(int i = 1;i <= n;i ++){
            if(a[i] == a[i + 2]){
                ans += a[i];
                color[i] = color[i + 2] = 1;
            }
        }
        cout << ans << endl;
    }
    return 0;
}
